<template>
  <div class="login-container">
    <h2>PlumGPT管理后台</h2>
    <form @submit.prevent="onSubmit">
      <div class="input-group">
        <label for="username">用户名：</label>
        <input type="text" id="username" v-model="username" required>
      </div>
      <div class="input-group">
        <label for="password">密码：</label>
        <input type="password" id="password" v-model="password" required>
      </div>
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods: {
    onSubmit() {
      if (!this.username){
        this.$message.error("账号不能为空")
        return
      }
      if (!this.password){
        this.$message.error("密码不能为空")
        return
      }
      this.$http.post('/admin/ht/login',{
        username:this.username,
        password:this.password
      }).then((res) => {
        if (res.data.code === 200){
          localStorage.setItem("token",res.data.token);
          this.$router.push("/chat")
        }else {
          this.$message.error(res.data.msg)
        }
      })
    }
  }
};
</script>

<style scoped>
body {
  background-color: #f9fbfd;
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
}

.login-container {
  background-color: white;
  border-radius: 10px;
  padding: 30px;
  width: 300px;
  margin: 100px auto;
  box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.1);
}

.input-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 15px;
}

label {
  margin-bottom: 5px;
  text-align: left;
}

input {
  border: 1px solid #484c7f;
  border-radius: 5px;
  padding: 5px;
  font-size: 14px;
  outline: none;
  height: 30px;
}

input:focus {
  border-color: #484c7f;
}

button {
  background-color: #484c7f;
  color: white;
  border-radius: 5px;
  border: none;
  padding: 10px 20px;
  margin-top: 10px;
  font-size: 14px;
  cursor: pointer;
}

button:hover {
  background-color: #3c416f;
}
</style>
